
package com.femass.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import com.femass.model.Revisor;
import com.femass.repository.RevisorRepository;
import com.femass.util.Repositorios;

@FacesConverter("revisorConverter")
public class RevisorConverter implements Converter{

    private Repositorios repositorios = new Repositorios();
    private RevisorRepository repoRevisores = this.repositorios.getRevisores();
    
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Revisor revisor = null;
        
        if(!value.equals("")){
            return (Revisor) this.repoRevisores.porCodigo(new Integer(value));
            
        }
        
        return revisor;
        
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        String retorno = null;
        
        if(value!=null){
            Integer codigo = ((Revisor)value).getCod();
            return codigo == null ? "" : codigo.toString();
        }
        
        return retorno;
    }
    
}
